<?php

namespace app\api\controller\user;

use app\api\controller\Controllers;
use app\api\service\user\UserCoupons as UserCouponsService;

class UserCoupons extends Controllers
{

    /**
     * 获取用户优惠券列表
     * @param UserCouponsService $service
     *
     * @return \think\Response
     */
    public function lists(UserCouponsService $service)
    {
        $list = $service->lists();
        return false === $list->isEmpty()?success($list):notFound();
    }

    /**
     * 获取可用优惠券列表
     * @param UserCouponsService $service
     * @param int $type
     * @throws \think\db\exception\ModelNotFoundException
     * @return \think\Response
     */
    public function available(UserCouponsService $service)
    {
        $post = $this->request->only(['type','price'], 'post');
        return success($service->available($post['type'], $post['price']));
    }

}
